// This kernel fetches data from global memory to kernel and 
// then directly stores them back to global memory
// Different accessing patterns are compared to the influences on bandwidth
// 2020.11.17 by wangdong@bjtu.edu.cn
#include <stdio.h>
#include "ap_axi_sdata.h"
#include "ap_int.h"
#include "hls_stream.h"

#define VEC_SIZE    16

typedef ap_uint<VEC_SIZE*32> data_vec;
//typedef struct {
//  ap_uint<32> data[VEC_SIZE];
//} data_vec;

typedef ap_axiu<VEC_SIZE*32,0,0,0> k2k_data;


extern "C" {
void DataLoad(
				const data_vec *A_in,  //HBM[0]
				const data_vec *C_in,  //HBM[2]
				const unsigned int data_num,
				hls::stream<k2k_data> &stream_out_0,
				hls::stream<k2k_data> &stream_out_1
				)
{
#pragma HLS INTERFACE m_axi port = A_in  offset = slave bundle = gmem0 depth = 32// group-0
#pragma HLS INTERFACE m_axi port = C_in  offset = slave bundle = gmem1 depth = 32// group-1
#pragma HLS INTERFACE axis port = stream_out_0 depth = 16
#pragma HLS INTERFACE axis port = stream_out_1 depth = 16

	k2k_data tmp1, tmp2;

	for(unsigned int i=0; i<data_num; i++){
		tmp1.data = A_in[i];
		tmp2.data = C_in[i];
		//blocking streaming access
		stream_out_0.write(tmp1);
		stream_out_1.write(tmp2);
    }

}
}
